//
//  WXLEveryCollectionReusableView.m
//  段子手
//
//  Created by dllo on 16/3/20.
//  Copyright © 2016年 JokesTeam. All rights reserved.
//

#import "WXLEveryCollectionReusableView.h"

@interface WXLEveryCollectionReusableView ()

@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UIButton *moreButton;

@end

@implementation WXLEveryCollectionReusableView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

- (void)createSubView {
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, self.bounds.size.width - 20 - self.bounds.size.width / 4, self.bounds.size.height)];
    [self addSubview:_titleLabel];
    _titleLabel.font = [UIFont systemFontOfSize:20 weight:0.5];
    
    self.moreButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [self addSubview:_moreButton];
    [_moreButton setTitle:@"更多 >" forState:(UIControlStateNormal)];
    [_moreButton setTitleColor:[UIColor colorWithWhite:0.355 alpha:1.000]forState:(UIControlStateNormal)];
    [_moreButton addTarget:self action:@selector(moreButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

- (void)setIndexPath:(NSIndexPath *)indexPath {
    if (_indexPath != indexPath) {
        _indexPath = indexPath;
    }
}

- (void)setModel:(WXLDataModel *)model {
    if (_model != model) {
        _model = model;
    }
    
    _titleLabel.text = _model.name;
    
    _moreButton.frame = CGRectMake(0, 0, 0, 0);
    
    if (![_model.type isEqualToString:@"0"]) {
        _moreButton.frame = CGRectMake(self.bounds.size.width - 100, 0, 90, self.bounds.size.height);
        
    }
}


#pragma mark - button 点击
- (void)moreButtonAction:(UIButton *)button {
    [self.delegate moreButtonActionClick:_indexPath.section];
}

@end
